<?php
/**
 * User Model
 * @author libai.tc@gmail.com
 */

class caModel
{
    private $_db;
    
    public function __construct() {
        $this->_db = new DB();
    }

	public function getCaLeaf() {
		$all_ca=$this->_db->get_all('select * from category');
		$result=array();
		foreach($all_ca as $item){
			if($item['father']!=0 && $item['root']!=0){
				$father=$this->findSqlArray($all_ca, 'id', $item['father']);
				$root=$this->findSqlArray($all_ca, 'id', $item['root']);
				$desc=$root['desc'] . '--' . $father['desc'] . '--' . $item['desc'];
				array_push($result, array('id'=>$item['id'], 'desc'=>$desc));
			}
		}
		return $result;
	}


	private function findSqlArray($array, $key, $value)
	{
		foreach($array as $item)
			if($item[$key]==$value)
				return $item;

		return false;
	}
}

/* ------ EOF ------ */
